﻿<cfsilent>
	<cfscript>

		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		response = structNew();
		structInsert(response, "success", false, true);
		
		examId = event.getArg("EXID");
		wid = event.getArg("WK");
		
		if ( wid gt 0 ) {
			newWeek = numberFormat(wid, "0_");
		}
		else {
			newWeek = wid;
		}

		transaction {
						
			/* 加载考试任务 */
			sql = "UPDATE t_resittask a 
					SET a.wid = :ExamWeek  
					WHERE a.task_exrstid = :examId ";
			
			queryObj = new Query( datasource=application.dnsMaster);
			queryObj.addParam( name="ExamWeek", value=newWeek, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="examId", value=examId, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );
			
			/* 数据密闭 */
			
			/* 如果已经保存了学生考试安排 则全部删除 */
		
			sql = "DELETE 
					FROM t_student_resit a 
					WHERE a.task_exrstid = :examId ";
					
			queryObj = new Query( datasource=application.dnsMaster);
			queryObj.addParam( name="examId", value=examId, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );
							
			/* 如果已经保存了场地占用 则全部删除 */
		
			sql = "DELETE 
					FROM t_clsroom_timetable a 
					WHERE a.crtime_id IN (
						  SELECT b.crtime_id 
						  FROM t_clsroom_forresit b 
						  WHERE b.task_exrstid = :examId 
					) ";
					
			queryObj = new Query( datasource=application.dnsMaster);
			queryObj.addParam( name="examId", value=examId, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );

			
			structInsert(response, "ExamID", examId, true);
			structInsert(response, "ExamWeek", newWeek, true);

			structInsert(response, "success", true, true);
			
		}
	


	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>